package club.justwill.single.persistence.jpo;

import club.justwill.single.persistence.support.OrderItemBase;
import club.justwill.single.persistence.support.OrderItemPK;

import javax.persistence.*;

/**
 * Created by luoyu on 15-12-24.
 */

@Entity
@Table(name = "order_item")
@IdClass(OrderItemPK.class)
public class OrderItem extends OrderItemBase {

    @Id
    @Column(name = "order_id")
    private long orderId;

    @Id
    @Column(name = "sku_id")
    private long skuId;

    //OrderItem跟Orders是多对一关系 多方
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "order_id", referencedColumnName = "order_id", insertable = false, updatable = false)
    private Orders orders;

    //OrderItme跟Skus是多对一关系 多方
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "sku_id", referencedColumnName = "sku_id", insertable = false, updatable = false)
    private Skus skus;

    public Orders getOrders() {
        return orders;
    }

    public void setOrders(Orders orders) {
        this.orders = orders;
    }

    public Skus getSkus() {
        return skus;
    }

    public void setSkus(Skus skus) {
        this.skus = skus;
    }

    public long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        if(orderId == null) {
            this.orderId = 0L;
        } else {
            this.orderId = orderId;
        }
    }

    public long getSkuId() {
        return skuId;
    }

    public void setSkuId(Long skuId) {
        if(skuId == null) {
            this.skuId = 0L;
        } else {
            this.skuId = skuId;
        }
    }

}
